<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item label="交易号：">
        <el-input v-model="dataForm.tradeNumber" maxlength="50" placeholder="交易号" clearable></el-input>
      </el-form-item>
      <el-form-item label="支付类型：" >
        <el-select v-model="dataForm.payType" clearable placeholder="请选择" style="width: 100px">
          <el-option
            v-for="(value, key)  in global.PayType"
            :key="key"
            :label="value"
            :value="key">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="支付状态：">
        <el-select v-model="dataForm.payState" clearable placeholder="请选择" style="width: 100px">
          <el-option
            v-for="(value, key)  in global.PayState"
            :key="key"
            :label="value"
            :value="key">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="业务类型：">
        <el-select v-model="dataForm.modeType" clearable placeholder="请选择" style="width: 150px">
          <el-option
            v-for="(value, key)  in global.UserFundModeType"
            :key="key"
            :label="value"
            :value="key">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间：">
        <time-picker ref="createTimePicker"  :datePattern="pattern" @pick="callbackPickTime"></time-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetQueryCondition()">重置</el-button>
        <el-button @click="getDataList()">查询</el-button>
       <!-- <el-button v-if="isAuth('simida:userfundlog:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="id">
      </el-table-column>
      <el-table-column
        prop="payUserId"
        header-align="center"
        align="center"
        label="支付人id">
      </el-table-column>
      <el-table-column
        prop="userFund"
        header-align="center"
        align="center"
        label="付款金额（元）">
        <template slot-scope="scope">
          <span v-text="(scope.row.userFund/100).toFixed(2)+' 元'"></span>
        </template>
      </el-table-column>
      <el-table-column
        prop="modeType"
        header-align="center"
        align="center"
        label="业务类型">
        <template slot-scope="scope">
          <div class="name-wrapper">
            <el-tag size="small">{{ global.UserFundModeType[scope.row.modeType]}}</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="tradeNumber"
        header-align="center"
        align="center"
        width="200"
        :show-overflow-tooltip="true"
        label="交易号">
      </el-table-column>
      <el-table-column
        prop="payState"
        header-align="center"
        align="center"
        label="支付状态">
        <template slot-scope="scope">
          <div class="name-wrapper">
            <el-tag size="medium">{{ global.PayState[scope.row.payState]}}</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="payType"
        header-align="center"
        align="center"
        label="支付类型">
        <template slot-scope="scope">
          <div class="name-wrapper">
            <el-tag size="medium">{{ global.PayType[scope.row.payType]}}</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        width="200"
        label="创建时间">
        <template slot-scope="scope">
          <i class="el-icon-time" v-if="scope.row.createTime"></i>
          <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="payTime"
        header-align="center"
        width="200"
        label="支付时间">
        <template slot-scope="scope">
          <i class="el-icon-time" v-if="scope.row.payTime"></i>
          <span style="margin-left: 10px">{{ scope.row.payTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="detail(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <user-fund-log-info ref="details" @refreshDataList="getDataList"></user-fund-log-info>
    <!-- 弹窗, 新增 / 修改 -->
   <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>-->
  </div>
</template>

<script>
  import AddOrUpdate from './userfundlog-add-or-update'
  import enums from '@/common/enum'
  import TimePicker from '@/views/time-picker'
  import UserFundLogInfo from './userfundlog-info'
  export default {
    data () {
      return {
        pattern:'yyyy-MM-dd hh:mm:ss',
        dataForm: {
          key: '',
          beginTime:'',
          endTime:'',
          tradeNumber:'',
          payType:'',
          payState:'',
          modeType:'',
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListSelections: [],
        addOrUpdateVisible: false,
        global:enums,
        detailVisible:false,
      }
    },
    components: {
      AddOrUpdate,
      TimePicker,
      UserFundLogInfo
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.$http({
          url: this.$http.adornUrl('/simida/userfundlog/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'tradeNumber': this.dataForm.tradeNumber,
            'payType':this.dataForm.payType,
            'payState':this.dataForm.payState,
            'modeType':this.dataForm.modeType,
            'beginTime':this.dataForm.beginTime,
            'endTime':this.dataForm.endTime
          },false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = [];
            this.totalPage = 0
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/simida/userfundlog/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      //详情点击
      detail(logId){
        this.detailVisible=true;
        this.$nextTick(()=>{
          this.$refs.details.details(logId)
        })
      },
      //时间控件回调
      callbackPickTime(data){
        this.dataForm.beginTime=data[0];
        this.dataForm.endTime=data[1];
      },
      //重置查询条件
      resetQueryCondition(){
         this.dataForm = {
           key: '',
           beginTime:'',
           endTime:'',
           tradeNumber:'',
           payType:'',
           payState:'',
           modeType:'',
         }
        this.$nextTick(()=>{
          this.$refs.createTimePicker.resetVal()
        })
      }
    }
  }
</script>
